const Joi = require("joi")

const userid = Joi.string().required()
const username = Joi.string()
  .alphanum()
  .required()
  .regex(/^[a-zA-Z][a-zA-Z0-9]{2,8}$/)
  .error(new Error("用户为必填项,且不能以数字开头的字母大小写与数字组成长度为3-9"))
const nickname = Joi.string().required()
const password = Joi.string().required().min(6).max(16)
const role = Joi.number()
const avatar = Joi.string().base64().optional()
const status = Joi.number()
module.exports = {
  addUser: Joi.object({
    username,
    nickname,
    password: password,
    confirmPassword: Joi.valid(Joi.ref("password")).error(new Error("两次密码必须保持一致")),
    role,
    avatar,
    status
  }),
  delUser: Joi.object({
    userid: Joi.string().required().error(new Error("请传入一个或多个id"))
  }),
  resetPassword: Joi.object({
    confirmPassword: Joi.not(Joi.ref("password"))
      .concat(password)
      .error(new Error("新密码不能与旧密码不能一样")),
    password: password
  }),
  updateUser: Joi.object({
    userid,
    username,
    nickname,
    role,
    avatar,
    status
  }),
  uesrList: Joi.object({
    pageNum: Joi.number().optional(),
    pageSize: Joi.number().optional(),
    username: Joi.optional()
  })
}
